import {showToastMsg} from "@/common/utils";

let baseUrl = 'http://localhost:8080/miniApp'
/**
 * 网络请求
 * @param {Object} obj
 */
const request = (obj) => {
    return new Promise((resolve, reject) => {
        uni.request({
            header: {
                'content-type': "application/json"
            },
            url: baseUrl + obj.url,
            method: obj.method || 'GET',
            timeout: 10000,
            data: obj.data || null,
            params: obj.params || null,
            success: (res) => {
                if (res.data.code === 200) {
                    resolve(res.data);
                } else {
                    showToastMsg('网络连接失败，请稍后重试');
                    reject(res);
                }
            },
            fail: (msg) => {
                showToastMsg('网络连接失败，请稍后重试');
                reject(msg);
            }
        });
    });
};


export default {request}